package com.fallsvc.dayproblem.demo202511;

import java.util.*;

/**
 * @auther falls_vc
 * description:
 * @date 2025/11/18  14:24
 */
public class Demo20251118 {
    //https://leetcode.cn/problems/h-index/?envType=study-plan-v2&envId=top-interview-150
    // H指数
    public int hIndex(int[] citations) {
        Arrays.sort(citations);

        int n = 0;// n篇超过
        int i = citations.length - 1;
        while(i >= 0 && citations[i] > n) {
            n++;
            i--;
        }
        return n;
    }
//    https://leetcode.cn/problems/recursive-mulitply-lcci/description/
    // 递归乘法
    public int multiply(int A, int B) {
        int min = Math.min(A,B);
        int max = Math.max(A,B);
        return mult(min,max);
    }
    public int mult(int min,int max) {
        if(min == 1) return max;

        return mult(min/2,max) + mult(min - min/2,max);
    }

    public static void main(String[] args) {
//        System.out.println(multiply(797231563,2));
    }
    public static void main1(String[] args) {
        Queue<Integer> q = new LinkedList<>();
        Stack<Integer> stack = new Stack<>();
        stack.isEmpty();
        stack.empty();
    }
    // https://leetcode.cn/problems/implement-queue-using-stacks/
    // 栈实现队列
    class MyQueue {
        private Stack<Integer> in;
        private Stack<Integer> out;


        public MyQueue() {
            in = new Stack<>();
            out = new Stack<>();
        }

        public void push(int x) {
            in.push(x);
        }

        public int pop() {
            if(out.isEmpty()) {
                inToOut();
            }

            return out.pop();
        }

        public int peek() {
            if(out.isEmpty()) {
                inToOut();
            }

            return out.peek();
        }

        public boolean empty() {
            return in.isEmpty() && out.isEmpty();
        }

        public void inToOut() {
            while(!in.empty()) {
                out.push(in.pop());
            }
        }
    }
    // 队列实现栈
    //https://leetcode.cn/problems/implement-stack-using-queues/
    class MyStack {
        private Queue<Integer> in;
        private Queue<Integer> out;

        public MyStack() {
            in = new LinkedList<>();
            out = new LinkedList<>();
        }

        public void push(int x) {
            in.offer(x);
            while(!out.isEmpty()) {
                in.offer(out.poll());
            }
            Queue<Integer> tmp = in;
            in = out;
            out = tmp;
        }

        public int pop() {
            return out.poll();
        }

        public int top() {
            return out.peek();
        }

        public boolean empty() {
            return out.isEmpty();
        }
    }
}
